package com.qf.java2201.dao.impl;

import com.qf.java2201.dao.CommentDao;
import com.qf.java2201.pojo.HComment;
import com.qf.java2201.utils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @date 2022/4/8
 * @desc
 */
public class CommentDaoImpl implements CommentDao {

    QueryRunner queryRunner = new QueryRunner(DbUtils.getDs());


    @Override
    public List<HComment> findCommentByDid(String did) {
        String sql="select * from h_comment c join h_order o on c.oid = " +
                " o.oid join h_userinfo u on o.edid = u.did where u.did = ?";
        //String sql2="select * from h_comment c join h_order o on c.oid = " +
        //        " o.oid  where o.edid = ?";

        List<HComment> query = null;
        try {
            query = queryRunner.query(sql, new BeanListHandler<>(HComment.class), did);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return query;
    }
}
